#include <iostream>
using namespace std;

const int kMaxN = 1010;
const int kMaxM = 1010;

int a[kMaxN][kMaxM];
int dp_lu[kMaxN][kMaxM], dp_ru[kMaxN][kMaxM], dp_ld[kMaxN][kMaxM], dp_rd[kMaxN][kMaxM];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i) {
        dp_lu[i][j] = max(dp_lu[i][j], dp_lu[i - 1][j]);
      }
      if (j) {
        dp_lu[i][j] = max(dp_lu[i][j], dp_lu[i][j - 1]);
      }
      dp_lu[i][j] += a[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (i) {
        dp_ru[i][j] = max(dp_ru[i][j], dp_ru[i - 1][j]);
      }
      if (j + 1 < m) {
        dp_ru[i][j] = max(dp_ru[i][j], dp_ru[i][j + 1]);
      }
      dp_ru[i][j] += a[i][j];
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (i + 1 < n) {
        dp_ld[i][j] = max(dp_ld[i][j], dp_ld[i + 1][j]);
      }
      if (j) {
        dp_ld[i][j] = max(dp_ld[i][j], dp_ld[i][j - 1]);
      }
      dp_ld[i][j] += a[i][j];
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (i + 1 < n) {
        dp_rd[i][j] = max(dp_rd[i][j], dp_rd[i + 1][j]);
      }
      if (j + 1 < m) {
        dp_rd[i][j] = max(dp_rd[i][j], dp_rd[i][j + 1]);
      }
      dp_rd[i][j] += a[i][j];
    }
  }

  int ans = 0;
  for (int i = 1; i + 1 < n; i++) {  // two pathes has only one cross point
    for (int j = 1; j + 1 < m; j++) {
      ans = max(ans, dp_lu[i - 1][j] + dp_ld[i][j - 1] + dp_ru[i][j + 1] + dp_rd[i + 1][j]);
      ans = max(ans, dp_lu[i][j - 1] + dp_ld[i + 1][j] + dp_ru[i - 1][j] + dp_rd[i][j + 1]);
    }
  }

  cout << ans << "\n";
  return 0;
}